import router from '../router'
import store from '../store'
import cookie from './store/cookie'

export default function toLogin (push, backUrl) {
  store.commit('LOGOUT')
  const { fullPath, name } = router.currentRoute
  cookie.set('login_back_url', backUrl || fullPath)

  if (name !== 'login') {
    push
      ? router.push({ name: 'login' })
      : router.replace({ name: 'login' })
  }
}
